package rssmanager.servlets;


import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import rssmanager.service.DBConnect;

/**
 * Servlet implementation class LogoutServlet
 */
public class EditRSSServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#HttpServlet()
	 */
	public EditRSSServlet() {
		super();
		// TODO Auto-generated constructor stub
	}

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

	}		


	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String nom_flux = request.getParameter("nom_flux");
		String lien_flux = request.getParameter("lien_flux");
		String id_flux = request.getParameter("id_flux");
		String msg="", error="";
		ResultSet rs;
		PreparedStatement stmt= null;
		System.out.println(nom_flux);
		System.out.println(lien_flux);
		System.out.println(id_flux);
		try {
			stmt = DBConnect.getConnection().prepareStatement("UPDATE fluxrss SET nom_flux = ?, lien_flux = ? WHERE id_flux = ?");
			stmt.setString(1, nom_flux);
			stmt.setString(2, lien_flux);
			stmt.setString(3, id_flux);
			msg = "Le flux a bien été modifié !";
			stmt.execute();                                                               
            stmt.close();                                                             
            stmt = null;  
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			error = "Erreur lors de la modification du flux";
			e.printStackTrace();
		}
		request.setAttribute("msg", msg);
		request.setAttribute("error", error);
		request.getRequestDispatcher("manager.jsp").forward(request, response);
	}

}
